#coding:utf-8
from django.db import models
from django.utils import timezone
from lovewith.supplier.models import ServiceCate
from lovewith.website.models import Color, Role, Category
from lovewith.account.models import MtUser


#share
class Post(models.Model):
    title = models.CharField(max_length=200, verbose_name=u'标题')
    content = models.TextField(blank=True, verbose_name=u'内容')
    post_date = models.DateTimeField(default=timezone.now, verbose_name=u'发布时间')
    cate = models.ForeignKey(Category, verbose_name=u'分类')
    user = models.ForeignKey(MtUser, verbose_name=u'用户')
    combo_path = models.TextField(max_length=255, blank=True, verbose_name=u'微博大图')
    is_video = models.SmallIntegerField(max_length=1, default=0, verbose_name=u'是否视频')
    video = models.CharField(max_length=255, blank=True, verbose_name=u'视频地址')
    #列表页优先显示推荐的分享
    is_recommend = models.SmallIntegerField(max_length=1, default=0, verbose_name=u'是否推荐')
    is_delete = models.SmallIntegerField(max_length=1, default=0, verbose_name=u'是否被删除')
    scheduled_enbale = models.SmallIntegerField(max_length=1, default=0, verbose_name=u'是否可预定')
    views = models.IntegerField(default=0, verbose_name=u'查看数')

    def __unicode__(self):
        return self.id

    class Meta:
        verbose_name_plural = u'帖子'
        db_table = 'mt_post'


#来源标注
class PostOrign(models.Model):
    share_post = models.ForeignKey(Post, related_name="post", verbose_name=u'分享')
    orign_user = models.CharField(max_length=30, verbose_name=u'来源用户')
    user_role = models.ForeignKey(Role, related_name="post_orign_role", verbose_name=u'来源用户角色')
    add_user = models.ForeignKey(MtUser, related_name="opt_user", verbose_name=u'操作者')
    add_date = models.DateTimeField(default=timezone.now, verbose_name=u'时间')

    def __unicode__(self):
        return self.orign_user

    class Meta:
        verbose_name_plural = u'帖子来源'
        db_table = 'mt_post_orign'


#评论
class PostComment(models.Model):
    share_post = models.ForeignKey(Post, verbose_name=u'分享')
    content = models.TextField(blank=True, verbose_name=u'评论内容')
    commen_date = models.DateTimeField(default=timezone.now, verbose_name=u'评论时间')
    user = models.ForeignKey(MtUser, verbose_name=u'评论用户')

    def __unicode__(self):
        return self.content

    class Meta:
        verbose_name_plural = u'评论'
        db_table = 'mt_post_comment'


#post image
class Attachment(models.Model):
    path = models.CharField(max_length=255, verbose_name=u'路径')
    is_cover = models.SmallIntegerField(default=0, verbose_name=u'封面')
    like = models.IntegerField(default=0)
    share_post = models.ForeignKey(Post, related_name='AttPost',)
    is_delete = models.SmallIntegerField(default=0, verbose_name=u'是否已删除')

    def __unicode__(self):
        return self.path

    class Meta:
        verbose_name_plural = u'图片'
        db_table = 'mt_attachment'


#like
class AttachLike(models.Model):
    post_image = models.ForeignKey(Attachment, verbose_name=u'图片')
    user = models.ForeignKey(MtUser, verbose_name=u'用户')

    class Meta:
        verbose_name_plural = u'喜欢'
        db_table = 'mt_attach_like'


#帖子服务类型
class AttachServiceType(models.Model):
    post_image = models.ForeignKey(Attachment, verbose_name=u'图片')
    service = models.ForeignKey(ServiceCate, verbose_name=u'服务类型')

    class Meta:
        verbose_name_plural = u'帖子服务类型'
        db_table = 'mt_attach_service_type'


#image tag
class AttachTag(models.Model):
    tagname = models.CharField(max_length=255, verbose_name=u'标签')
    post_image = models.ForeignKey(Attachment, related_name='TagAttach', verbose_name=u'图片')
    cate = models.ForeignKey(Category, verbose_name=u'分类')
    click_num = models.IntegerField(default=0)

    def __unicode__(self):
        return self.tagname

    class Meta:
        verbose_name_plural = u'图片标签'
        db_table = 'mt_attach_tag'


#color
class AttachColor(models.Model):
    share_post = models.ForeignKey(Post)
    post_image = models.ForeignKey(Attachment, verbose_name=u'图片')
    color = models.ForeignKey(Color, verbose_name=u'色值')

    class Meta:
        verbose_name = u'图片颜色'
        db_table = 'mt_attach_color'


#商品标注
class AttachGoods(models.Model):
    user = models.ForeignKey(MtUser, verbose_name=u'用户')
    cate = models.ForeignKey(Category, verbose_name=u'所属分类')
    post_image = models.ForeignKey(Attachment, related_name='GoodsAttach', verbose_name=u'图片')
    tagname = models.CharField(max_length=100, blank=True, verbose_name=u'商品标签')
    product_name = models.CharField(max_length=255, verbose_name=u'名称')
    product_url = models.CharField(max_length=255, verbose_name=u'连接')
    product_price = models.CharField(max_length=10, verbose_name=u'价格')
    flag_position = models.CharField(max_length=16, verbose_name=u'位置')
    post_date = models.DateTimeField(default=timezone.now, verbose_name=u'时间')

    def __unicode__(self):
        return self.product_name

    class Meta:
        verbose_name_plural = u'打标商品'
        db_table = 'mt_attach_goods'


#发布预设标签
class MtPresetTag(models.Model):
    tag = models.CharField(max_length=255, verbose_name=u'关键词')
    tag_related = models.TextField(verbose_name=u'相关关键词')

    class Meta:
        verbose_name_plural = u'发帖页预设标签'
        db_table = 'mt_preset_tag'